package com.dev.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import com.dev.bbs.bean.BbsSignInfo;
import com.dev.bbs.domain.BbsArticle;
import com.dev.bbs.domain.BbsUser;
import com.dev.bbs.service.IBbsArticleService;
import com.dev.bbs.service.IBbsUserSignService;
import com.dev.common.config.Global;
import com.dev.common.core.controller.BaseController;
import com.dev.framework.util.ShiroUtils;
import com.github.pagehelper.PageHelper;

/**
 * 首页 业务处理
 * 
 * @author ruoyi
 */
@Controller
public class BbsIndexController extends BaseController
{
    @Autowired
    private IBbsArticleService    articleService;

    @Autowired
    private IBbsUserSignService bbsUserSignService;

    // 系统首页
    @GetMapping("/")
    public String index(ModelMap mmap)
    {
        // 取身份信息
        BbsUser user = ShiroUtils.getBbsUser();
        PageHelper.startPage(1, 20);
        BbsArticle querArticle=new BbsArticle().setDelFlag(false);
        List<BbsArticle> articles = articleService.selectBbsArticleList(querArticle);
        List<BbsArticle> recs = articleService.selectBbsArticleList(querArticle.setTop(true));
        mmap.put("user", user);
        mmap.put("articles", articles);
        mmap.put("recs", recs);
        mmap.put("copyrightYear", Global.getCopyrightYear());
        mmap.put("demoEnabled", Global.isDemoEnabled());
        BbsSignInfo sign = null;
        if (user != null)
        {
            sign = bbsUserSignService.getSign(user.getUserId());
        }
        else
        {
            // 未登录
            sign = new BbsSignInfo();
        }
        mmap.put("sign", sign);
        // 签到信息
        return "index";
    }
}
